<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<script type="text/javascript" src="${pageContext.request.contextPath }/static/js/jquery-3.3.1.js"></script>
<link rel="stylesheet" href="${pageContext.request.contextPath }/static/css/jquery.datetimepicker.css">
	<script src="${pageContext.request.contextPath }/static/js/jquery.datetimepicker.js"></script>
	<link rel="stylesheet" href="${pageContext.request.contextPath }/static/css/ion.calendar.css">
	<script src="${pageContext.request.contextPath }/static/js/moment.min.js"></script>
	<script src="${pageContext.request.contextPath }/static/js/moment.zh-cn.js"></script>
	<script src="${pageContext.request.contextPath }/static/js/ion.calendar.min.js"></script>
	<link rel="stylesheet" href="${pageContext.request.contextPath }/static/css/demo1.css">
	<link rel="stylesheet" href="${pageContext.request.contextPath }/static/css/avgrund.css">
	<script type="text/javascript" src="${pageContext.request.contextPath }/static/js/avgrund.js"></script>
	<script type="text/javascript" src="${pageContext.request.contextPath }/static/js/nav.js"></script>
	<link rel="stylesheet" href="${pageContext.request.contextPath }/static/css/schedule.css">
	<link rel="stylesheet" href="${pageContext.request.contextPath }/static/css/demo9.css">
	<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath }/static/css/menu_sideslide.css" />
	<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath }/static/css/normalize.css" />
	<%-- <link rel="stylesheet" href="${pageContext.request.contextPath }/static/css/jquery.mCustomScrollbar.css">
    <script src="${pageContext.request.contextPath }/static/js/jquery.mCustomScrollbar.concat.min.js"></script> --%>
    <script type="text/javascript">

 function sendMessage(user1){
	
		    var user=user1;
		    var send="<%=request.getParameter("user")%>";
		    var msg="我给你分享了一个日常安排";
		    var param_data={
					  'user':user,
					  'send':send,
					  'msg':msg
			  };
		   
			$.ajax({        			
				type:"GET",
			    url:"/Schedule/AddMessage.action",
			    contentType:"application/json;charset=utf-8",  
			    //我们使用 JSON.stringify() 方法处理json，将其转换为字符串；
			    data:{
			    	'param':JSON.stringify(param_data)
			    },
			    dataType:"json",
			    async:false,
			    success:function(data){
			    	if(data.code==1)
			    	    alert("分享发送成功");	    	
			    }        		    
			});   //ajax

 }
 
 function shareSchedule(user1,theme,start,end,staff,ins){
	
	   var te=start.split(" ");
	   var en=end.split(" ");
        var user=user1;
	    var theme=theme;
	    var start_date=te[0];
	    var start_time=te[1];
	    var end_date= en[0];
	    var end_time=en[1];
	    var staff= staff;
	    var warn= "提醒";
	    var instruction=ins+" "+"<%=request.getParameter("user")%>"+"分享给你的安排";
	    
	    var param_data={
				  'user':user,
				  'theme':theme,
				  'start_date':start_date,
				  'start_time':start_time,
				  'end_date':end_date,
				  'end_time':end_time,
				  'staff':staff,
				  'warn':warn,
				  'instruction':instruction,
			  
		  };
	   
		$.ajax({        			
			type:"GET",
		    url:"/Schedule/shareSchedule.action",
		    contentType:"application/json;charset=utf-8",  
		    //我们使用 JSON.stringify() 方法处理json，将其转换为字符串；
		    data:{
		    	'param':JSON.stringify(param_data)
		    },
		    dataType:"json",
		    async:false,
		    success:function(data){
		    	if(data.code==1){
		    		  //alert("日程分享添加成功");	
		    	}
		    	      	
		    }        		    
		});   //ajax

 }
    
</script>

	<script type="text/javascript">
		$(function(){
		
		
		$(".start_date").datetimepicker({
            lang:'ch',
            format:'Y-m-d',
            formatDate:'Y-m-d',
            timepicker:false
        });
        $(".end_date").datetimepicker({
            lang:'ch',
            format:'Y-m-d',
            formatDate:'Y-m-d',
            timepicker:false
        });
		});

        $(function(){
            $("#calendar").ionCalendar({
                lang: 'zh-cn',
                format: 'YYYY年M月D日',
                onClick: function(date){
                	var code = "<%=request.getParameter("code")%>";
                	
                	if(code==1){
                	var time=new Date(Date.parse(date.replace('年','-').replace('月','-').replace('日','')))
                    console.log(time)
                    var d=new Date(time);
                    var year=d.getFullYear();
                    var month=change(d.getMonth()+1);
                    var day=change(d.getDate());
                    var time=year+'-'+month+'-'+day;
                    
                    openDialog();
                    function change(t){
                        if(t<10){
                            return "0"+t;
                        }else{
                            return t;
                        }
                    }
                    var user="<%=request.getParameter("user")%>"
                    var param_data={
                    	'user':user,
                    	'start_date':time
                    }
                    $.ajax({
                    	type:"POST",
                        url:"${pageContext.request.contextPath }/selectSchedule.action",
                        data:{'param':JSON.stringify(param_data)},
                        dataType:"json",
                        async:false,
                        success:function(data){
                        	console.log(data)
                            if(data != ""){
           						var tbl=""
           						
           						var text3="edit_sch"
                       		 	for(var i=0;i<data.length;i++){
                       		 	var text1="${pageContext.request.contextPath }/deleteSchedule.action?id="+data[i].id
               					var text2="${pageContext.request.contextPath }/SelectOne.action?id="+data[i].id
                       			 tbl+="<p><span>主题</span>：<span>"+data[i].theme+"</span></p><p><span>开始时间</span>：<span>"+data[i].start_date+" "+data[i].start_time+"</span></p><p><span>结束时间</span>：<span>"+data[i].end_date+" "+data[i].end_time+"</span></p><p><span>人员</span>：<span>"+data[i].staff+"</span></p><p><span>说明</span>：<span>"+data[i].instruction +"</span></p>"+"<p><a href='"+text1+"'>删除</a>"+"<a href='"+text2+"' class='"+text3+"'>修改</a></p>"
                       		}  		    	
                 		     $(".detail_content").html(tbl);
                            }else{       
                            	$(".detail_content").html("您没有添加事件");
                            }
                        }
                    });
                    
                    
                }else{
                	alert("您还未登录！");
                }
                }
            
            });
            
        });
	</script>
	<script type="text/javascript">

        function openDialog() {
            Avgrund.show( "#default-popup" );
        }

        function closeDialog() {
            Avgrund.hide();
        }

	</script>
	
	
	<script type="text/javascript">
		$(function(){
			
			$(".input_theme").blur(function(){
				$(".formtips").remove();
				if($(this).val()==""){
	                   $(this).after("<span class='formtips'>不能为空</span>")
	               }else{
	                   return;
	               }
			});
			$(".form_submit").click(function(){
				var theme=$(".input_theme").val()
				if(theme==""){
					alert("添加失败");
				}else{
					$(this).prop("type","submit");
				}
			});
		});
	</script>
	<script type="text/javascript">
        $(document).ready(function(){
        	var code = "<%=request.getParameter("code")%>";
        	if(code==0){
        		
                 
                var ch22 = document.getElementById("login");
                ch22.style.visibility="visible";
        	}else if(code==1){
        		
                 
                var ch22 = document.getElementById("login");
                ch22.style.visibility="hidden";
                
        	}
        	$("#pt").click(function(){
        	    var name="<%=request.getParameter("user")%>";
        	    location.href="pingtu.jsp?code=1&user="+name;
        	});
        	
           
        });
    </script>
    <script type="text/javascript">
    $(function () {
    	$("#bt").on("click",function(){
    		var code = "<%=request.getParameter("code")%>";
    		$(".right_form").find("img").remove();
    		$(".right_form").find("p").remove();
    		$(".right_form").find("table").remove();
    		if(code==1){
    			var user="<%=request.getParameter("user")%>"
    			var param_data={
                    	'user':user,
                    }
 					console.log(JSON.stringify(param_data))
    			$.ajax({
    				type:"POST",
                    url:"${pageContext.request.contextPath }/selectAllSchedule.action",
                    data:JSON.stringify(param_data),
                    contentType:"application/json;charset=utf-8",
                    dataType:"json",
                    async:false,
                    success:function(data){
                    	console.log(data)
                    	if(data==""){
                    		$(".right_form").append("<img src='../img/bk.gif' style='width:400px;height:400px'><p style='font-size:25px;margin-left:100px'>你还未添加倒计时</p>")
                    	}else{
                    		/* alert("交互成功"); */
                    		var tbl = "<table>";
                    		 tbl+="<tr><td style='"+"width: 150px;height: 40px"+"'>主题</td><td style='"+"width: 200px;height: 40px"+"'>开始时间</td><td style='"+"width: 200px;height: 40px"+"'>结束时间</td><td style='"+"width: 150px;height: 40px"+"'>人员</td><td style='"+"width: 150px;height: 40px"+"'>说明</td></tr>"
                    		 for(var i=0;i<data.length;i++){
                    			 var text1="${pageContext.request.contextPath }/deleteSchedule.action?id="+data[i].id;
                    			 var text2="${pageContext.request.contextPath }/SelectOne.action?id="+data[i].id;
                    			 var text3="editcount"
                    			 var text4="nexttime"
                    			 var text5="informtime"
                    			 var text6="#"
                    			 var text7=""
                    			 var text8="share"
                    			 tbl+="<tr><td style='"+"width: 150px;height: 40px"+"'>"+data[i].theme+"</td><td style='"+"width: 200px;height: 40px"+"' class='"+text4+"'>"+data[i].start_date+" "+data[i].start_time+"</td><td style='"+"width: 200px;height: 40px"+"'>"+data[i].end_date+" "+data[i].end_time+"</td><td style='"+"width: 150px;height: 40px"+"' class='"+text5+"'>"+data[i].staff+"</td><td style='"+"width: 150px;height: 40px"+"' class='"+text6+"'>"+data[i].instruction+"</td><td><a href='"+text1+"'>删除</a></td>"+"<td><a href='"+text2+"' class='"+text3+"'>修改</a></td><td><span  class='"+text8+"'>分享</span></td></tr>"
                    		 }
                    		 $(".right_form").html(tbl);
                    	}
                    }
    			});
    			$(".right_form").show()
    		}
    		
    		else{
    			alert("您还未登录！");
    		}
    		});
    	$('#bt').trigger("click");
});
</script>
<script type="text/javascript">
	$(function(){
		var share_btn = document.getElementsByClassName("share");
    	var theme;
    	var start_time;
    	var end_time;
    	var staff;
    	var ins;
    	/* console.log(share_btn) */
    	for(var i=0;i<share_btn.length;i++){
    		(function(e) {
    		share_btn[e].onclick=function(){
    			/* console.log(share_btn[e]) */
    			 theme = $(".right_form table").find("tr").eq(e+1).find("td").eq(0).text();
    			/* console.log(theme); */
    			start_time = $(".right_form table").find("tr").eq(e+1).find("td").eq(1).text();
    			/* console.log(start_time); */
    			 end_time = $(".right_form table").find("tr").eq(e+1).find("td").eq(2).text();
    			/* console.log(end_time); */
    			staff = $(".right_form table").find("tr").eq(e+1).find("td").eq(3).text();
    			/* console.log(staff); */
    			ins = $(".right_form table").find("tr").eq(e+1).find("td").eq(4).text();
    			/* console.log(ins); */
    			
    			
    			
    			openDialog();
			$("#default-popup").find("h2").empty();
			$("#default-popup").find("div").empty();
			var user="<%=request.getParameter("user") %>";			  
	  		$.ajax({        			
	  			type:"GET",
	  		    url:"/Schedule/FindFriends.action",
	  		    contentType:"application/json;charset=utf-8",  
	  		    //我们使用 JSON.stringify() 方法处理json，将其转换为字符串；
	  		    data:{
	  		    	'user':user
	  		    },
	  		    dataType:"json",
	  		    async:false,
	  		    success:function(result){
	  		    	   	
	  		    	    if(result.code==1){
	  		    	    	
			    	    	var data=result.data;
			    	    	var tbl="<h2>好友列表</h2>"
			    	    	tbl += "<table > <tr style='height: 35px'> <div class='frienddt'>"; 
			    	    	tbl+="<td class='name'>姓名&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td> <td class='phone'>电话</td></div></tr>";	

	             		    for(var i=0;i<data.length;i++){
	             			 
	             			tbl+="<tr style='height: 35px'>  <div class='frienddt'> "
	             			tbl+="<td class='name'>"+data[i].name+"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td> <td class='phone'>"+data[i].phone+"</td><td>";
	             			tbl +="<input id='share' type='button' value='分享' style='margin-left:20px;width:50px;background-color:#EEE0E5' ";
	             			tbl +=
	             				'onclick="sendMessage(\''
	             				+data[i].user
	             				+'\');shareSchedule(\''
	             				+data[i].user
	             				+'\',\''+ theme 
	             				+'\',\'' + start_time 
	             				+' \',\''+ end_time 
	             				+' \',\''+ staff 
	             				+' \',\''+ ins 
	             				+' \');">';

	             			tbl +="</td></tr>";
	             			

	             			
	             		 }
	             		   tbl+="<button onClick='javascript:closeDialog();' style='float: right;margin-top:-30px;'>Close</button>";   
	             		  
	          		       tbl+="</table>";   		    	
	          		       $("#default-popup").html(tbl);
			    	    }
	  		    }        		    
	  		});   //ajax
    			
    		}
    	})(i);
    	}
    	
    	
// 		$(".share").click(function(){
// 			openDialog();
// 			$("#default-popup").find("h2").empty();
// 			$("#default-popup").find("div").empty();
<%-- 			var user="<%=request.getParameter("user") %>";			   --%>
// 	  		$.ajax({        			
// 	  			type:"GET",
// 	  		    url:"/Schedule/FindFriends.action",
// 	  		    contentType:"application/json;charset=utf-8",  
// 	  		    //我们使用 JSON.stringify() 方法处理json，将其转换为字符串；
// 	  		    data:{
// 	  		    	'user':user
// 	  		    },
// 	  		    dataType:"json",
// 	  		    async:false,
// 	  		    success:function(result){
	  		    	   	
// 	  		    	    if(result.code==1){
	  		    	    	
// 			    	    	var data=result.data;
// 			    	    	var tbl="<h2>好友列表</h2>"
// 			    	    	tbl += "<table > <tr style='height: 35px'> <div class='frienddt'>"; 
// 			    	    	tbl+="<td class='name'>姓名&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td> <td class='phone'>电话</td></div></tr>";	

// 	             		    for(var i=0;i<data.length;i++){
	             			 
// 	             			tbl+="<tr style='height: 35px'>  <div class='frienddt'> "
// 	             			tbl+="<td class='name'>"+data[i].name+"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td> <td class='phone'>"+data[i].phone+"</td><td><input id='share' type='button' value='分享' style='margin-left:20px;width:50px;background-color:#EEE0E5'"+ 'onclick="sendMessage(\''+data[i].user+'\');shareSchedule(\''+data[i].user+'\');">'+"</td></tr>";
// 	             			tbl+="<button onClick='javascript:closeDialog();' style='float: right;margin-top:-30px;'>Close</button>";
	             			
	             			
// 	             		 }
	           		     
// 	          		       tbl+="</table>";   		    	
// 	          		       $("#default-popup").html(tbl);
// 			    	    }
// 	  		    }        		    
// 	  		});   //ajax
	  		
// 		});//share
		
		
		
	});

</script>
    <script type="text/javascript">
    $(function () {
    	$("#showdt").click(function(){
			if($("#info").css("display")=="none"){
				var user="<%=request.getParameter("user")%>";
				
				$.ajax({        			
        			type:"GET",
        		    url:"/Schedule/findPerson.action",
        		    contentType:"application/json;charset=utf-8",  
        		    //我们使用 JSON.stringify() 方法处理json，将其转换为字符串；
        		    data:{
        		    	'user':user
        		    },
        		    dataType:"json",
        		    async:false,
        		    success:function(result){
        		   
        		    	 if(result.code==1){
        		    		
        		    		 var data=result.data;
        		    			        		    		  		    	
//         		    	 $("#da1").val(data.user);
                 		 $("#da3").val(data.name);
                 		 $("#da4").val(data.phone);
                 		 $("#da5").val(data.address);
                 		 
                 		     
        		    	 }else if(result.code==-1){
        		    		 alert("获取用户失败");
        		    	 }      		    	
        		    }        		    
        		});   
				
				$("#info").show();
				
				
			}else{
				$("#info").hide();
			}
		});
		
		$("#save").click(function(){
			
			var user="<%=request.getParameter("user") %>";
     		var name= $("#da3").val();
     		var phone= $("#da4").val();
     		var address=$("#da5").val();
     		
     		var param_data1={                				
  					'user':user,              				
  					'name':name,
    				'phone':phone,
    				'address':address
      	  }
      	  console.log(JSON.stringify(param_data1));
          
          $.ajax({        			
  			type:"GET",
  		    url:"/Schedule/updatePerson.action",
  		    contentType:"application/json;charset=utf-8",  
  		    //我们使用 JSON.stringify() 方法处理json，将其转换为字符串；
  		    data:{'param':JSON.stringify(param_data1)},
  		    dataType:"json",
  		    async:false,
  		    success:function(result){
  		    	 //var  data=JSON.parse(result);//转换成json对象
  		    	 if(result.code==1){
  		    		alert("修改成功");
  		    	 }else{
  		    		 alert("修改失败");
  		    	 }      		    	
  		    }        		    
  		}); //ajax
          
          
		});//save
	});
    </script>
<title>时间安排</title>
</head>
<body >
<div class="container">
			<div class="menu-wrap">
				<p class="pp">
					当前用户:  
					<span style="font-size: 20px" onclick="" id="showdt">&nbsp;&nbsp;&nbsp;<%=request.getParameter("user") %></span>
				</p>
				<div id="info"  style="height: 150px;display: none;" >

				        <span><font  color="#FFFFFF">&nbsp;密&nbsp;&nbsp;&nbsp;码:&nbsp;&nbsp;&nbsp;</font><input type="password" id="da2" style="margin-left:15px" value="******"></span>
				        <br>
				        <span><font  color="#FFFFFF">&nbsp;姓&nbsp;&nbsp;&nbsp;名:&nbsp;&nbsp;&nbsp;</font>：<input type="text" id="da3" style="margin-left:15px"></span>
				        <br>
				        <span><font  color="#FFFFFF">&nbsp;手&nbsp;&nbsp;&nbsp;机:&nbsp;&nbsp;&nbsp;</font><input type="text" id="da4" style="margin-left:15px"></span>
				        <br>
				        <span><font  color="#FFFFFF">&nbsp;邮&nbsp;&nbsp;&nbsp;箱:&nbsp;&nbsp;&nbsp;</font><input type="text" id="da5" style="margin-left:15px"></span>
				        <br>
				        
				        
				       <button id="save" style="color:black;margin-left:90px;margin-top:10px">保存</button>

				     </div>
				<div  class="out">
					
					<a id="loginout" data-target="" href="../static/jsp/main.jsp?code=0"><i class="fa fa-fw fa-newspaper-o"></i><span>退出</span></a>
				</div>
				<nav class="menu">
					<div class="icon-list">
						
					</div>
				</nav>
				<button class="close-button" id="close-button">Close Menu</button>
			</div>
			<button class="menu-button" id="open-button">Open Menu</button>
<div class="header" style="background: #373a47">
	
	<div class="header_nav">
		<ul class="ul1">
			<li><a href="../static/jsp/main.jsp?code=<%=request.getParameter("code")%>&user=<%=request.getParameter("user")%>">首页</a></li>
			<li><a href="schedule.jsp?code=<%=request.getParameter("code")%>&user=<%=request.getParameter("user")%>">日程安排</a>
			</li>
			<li id="bt"><a href="backtime.jsp?code=<%=request.getParameter("code")%>&user=<%=request.getParameter("user")%>">倒计时</a>
			</li>
			<li>益智小游戏
                <ul class="ul2">
                   
                    <li id="pt"><font class="ping">拼图</font></li>
                    <li><a href="lianliankan.jsp?code=<%=request.getParameter("code") %>&user=<%=request.getParameter("user") %>" style="margin-left:3px;">连连看</a></li>                
                </ul>
            </li>
            <li><a href="robot.jsp?code=1&user=<%=request.getParameter("user")%>">智能机器人</a></li>
        </ul>
    </div>
    <ul class="register">
        
        <li id="message"><a href="message.jsp?code=1&user=<%=request.getParameter("user") %>">消息</a></li>
        <li id="login"><a href="login.jsp">登录</a></li>
    </ul>
</div>
<div class="content" style="background: url(../img/bk.jpg);background-size:cover;">
	<div class="content_left">
		<div class="left_weather">
			<iframe name="weather_inc" src="http://i.tianqi.com/index.php?c=code&id=55"  width="255" height="294" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe>
		</div>
		<div class="jq22">
			<div id="calendar"></div>
		</div>
	</div>
	<div class="content_right">
		<div class="right_title">
			<a href="../static/jsp/addschedule.jsp?code=1&user=<%=request.getParameter("user")%>">添加日程</a>
		</div>
		<div class="right_form" >
			
				
		</div>
	</div>
	
</div>
<div class="avgrund-cover"></div>
<aside id="default-popup" class="avgrund-popup">
	<h2>今日安排</h2>
	<div class="detail_content" style="height: 196px;overflow: auto" >
		
	</div>
	<button onClick="javascript:closeDialog();" style="float: right;margin-top:10px">Close</button>

</aside>

</div>	
	<script src="${pageContext.request.contextPath }/static/js/classie.js"></script>
	<script src="${pageContext.request.contextPath }/static/js/main.js"></script>
</body>
</html>